import 'package:flutter/material.dart';
import 'package:local_coffee/components/icon.dart';
import 'package:local_coffee/components/rgba.dart';
import 'package:local_coffee/components/hex.dart';
import 'package:local_coffee/jsonserialize/goods_list/data.dart';

class RecommendGoods extends StatelessWidget {
  
  final Function(int) onPress;
  final GoodsListDatum data;

  /// 推荐商品
  RecommendGoods({
    this.data,
    this.onPress
  });

  /// 商品图片
  Widget goodsImg(String imgSrc) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(0),
      child: Image.network(
        imgSrc,
        width: 108,
        height: 108,
        fit: BoxFit.cover,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    String desc = data.characteristic;

    desc = desc.length > 20 ? desc.substring(0, 18) + '...' : desc;

    return GestureDetector(
      onTap: () => onPress(data.id),
      child: Container(
        width: 108,
        color: HEX.hexfff,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text(
              '${data.name}',
              style: TextStyle(
                fontSize: 11,
                color: RGBA.rgba383838,
                fontWeight: FontWeight.bold
              ),
            ),
            Text(
              '$desc',
              style: TextStyle(
                color: RGBA.rgbaa6a6a6,
                fontSize: 10
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 15),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Container(
                        child: Text(
                          '${data.originalPrice}',
                          style: TextStyle(
                            fontSize: 12,
                            color: RGBA.rgbaff8d1a,
                            fontWeight: FontWeight.bold
                          ),
                        ),
                      )
                    ],
                  ),
                  icon0xe6e0(
                    color: RGBA.rgba94c4ec,
                    size: 24
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}